package com.ruoyi.experiment.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.experiment.mapper.ExperimentRecordMapper;
import com.ruoyi.experiment.domain.ExperimentRecord;
import com.ruoyi.experiment.service.IExperimentRecordService;

/**
 * 过程记录Service业务层处理
 * 
 * @author gw
 * @date 2025-01-08
 */
@Service
public class ExperimentRecordServiceImpl implements IExperimentRecordService 
{
    @Autowired
    private ExperimentRecordMapper experimentRecordMapper;

    /**
     * 查询过程记录
     * 
     * @param recordId 过程记录主键
     * @return 过程记录
     */
    @Override
    public ExperimentRecord selectExperimentRecordByRecordId(Long recordId)
    {
        return experimentRecordMapper.selectExperimentRecordByRecordId(recordId);
    }

    /**
     * 查询过程记录列表
     * 
     * @param experimentRecord 过程记录
     * @return 过程记录
     */
    @Override
    public List<ExperimentRecord> selectExperimentRecordList(ExperimentRecord experimentRecord)
    {
        return experimentRecordMapper.selectExperimentRecordList(experimentRecord);
    }

    /**
     * 新增过程记录
     * 
     * @param experimentRecord 过程记录
     * @return 结果
     */
    @Override
    public int insertExperimentRecord(ExperimentRecord experimentRecord)
    {
        experimentRecord.setCreateTime(DateUtils.getNowDate());
        experimentRecord.setCreateBy(SecurityUtils.getUsername());
        return experimentRecordMapper.insertExperimentRecord(experimentRecord);
    }

    /**
     * 修改过程记录
     * 
     * @param experimentRecord 过程记录
     * @return 结果
     */
    @Override
    public int updateExperimentRecord(ExperimentRecord experimentRecord)
    {
        experimentRecord.setUpdateTime(DateUtils.getNowDate());
        experimentRecord.setUpdateBy(SecurityUtils.getUsername());
        return experimentRecordMapper.updateExperimentRecord(experimentRecord);
    }

    /**
     * 批量删除过程记录
     * 
     * @param recordIds 需要删除的过程记录主键
     * @return 结果
     */
    @Override
    public int deleteExperimentRecordByRecordIds(Long[] recordIds)
    {
        int deletedCount = 0;
        for (Long recordId : recordIds) {
            ExperimentRecord experimentRecord = experimentRecordMapper.selectExperimentRecordByRecordId(recordId);
            experimentRecord.setDeleteBy(SecurityUtils.getUsername());
            experimentRecord.setDeleteTime(DateUtils.getNowDate());
            experimentRecord.setDelFlag(1);
            experimentRecordMapper.updateExperimentRecord(experimentRecord);
            deletedCount ++;
        }
        return deletedCount;
    }

    /**
     * 删除过程记录信息
     * 
     * @param recordId 过程记录主键
     * @return 结果
     */
    @Override
    public int deleteExperimentRecordByRecordId(Long recordId)
    {
        ExperimentRecord experimentRecord = experimentRecordMapper.selectExperimentRecordByRecordId(recordId);
        experimentRecord.setDeleteBy(SecurityUtils.getUsername());
        experimentRecord.setDeleteTime(DateUtils.getNowDate());
        experimentRecord.setDelFlag(1);
        return experimentRecordMapper.updateExperimentRecord(experimentRecord);
    }
}
